<%@page import="weaver.conn.RecordSet"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="com.zlgs.cqyf.vote.ConnectionUtil"%>
<%@ page import="com.alibaba.fastjson.*" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.sql.ResultSet" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
    JSONObject retObject = new JSONObject();
    retObject.put("code", 200);
    retObject.put("msg", "操作成功");
    try {
    	RecordSet set = new RecordSet();
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // URL 参数
        Integer dateType = Integer.parseInt(request.getParameter("dateType"));
        JSONArray array = new JSONArray();
        if(dateType != null ){
            // 数据库查询
            
            String sql = "select * from vote_awards where id in (" +
                    "SELECT a.awards_id FROM vote_awards_subname a " +
                    "LEFT JOIN vote_awards b ON a.awards_id= b.id " +
                    "WHERE b.is_del = 0 AND b.date_type=" +dateType.intValue()+
                    " AND a.is_del= 0 AND a.status IN( 1,- 1) GROUP BY a.awards_id HAVING COUNT ( a.awards_id ) >0" +
                    ")";
            set.executeSql(sql);
            while(set.next()){
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("id",set.getString("id"));                       	// 奖项配置id
                jsonObject.put("name",set.getString("name"));                 	// 奖项配置名称
	            jsonObject.put("startTime",   set.getString("start_time"));        	  						// 开始时间
	            jsonObject.put("endTime", set.getString("end_time"));        	  						// 开始时间
                jsonObject.put("dateType",set.getString("date_type"));           	// 时间类型：1 年度 2 季度
                jsonObject.put("about",set.getString("about"));           		//  
                jsonObject.put("regular",set.getString("regular"));           	//  
                jsonObject.put("votes",set.getString("votes"));           			//  
                jsonObject.put("votessame",set.getString("votes_same"));           //  
                jsonObject.put("createTime",set.getString("create_time")); 
                array.add(jsonObject);
            }
        }
        retObject.put("data", array);
    } catch (Exception e) {
        e.printStackTrace();
        retObject.put("code", -1);
        retObject.put("msg", e.getMessage());
    } finally {
        PrintWriter printWriter = response.getWriter();
        printWriter.append(retObject.toJSONString());
        
    }
%>
 